﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PreviewHandler.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the PreviewHandler class that inherits the Page class and handles *.preview requests.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Lidocaine.Service
{
    using System;
    using System.Globalization;
    using System.Web.UI.WebControls;
    using Lidocaine.BusinessLogic;
    using Lidocaine.BusinessObjects;

    /// <summary>
    /// Defines the PreviewHandler class.
    /// </summary>
    public class PreviewHandler : PageManager
    {
        protected override PageLayout SelectPage()
        {
            return PageLayoutManager.GetPageLayout(Request.Path.TrimStart("/".ToCharArray()).Replace(".preview", ".aspx"));
        }

        protected override PlaceHolder SelectMain(PageLayout page)
        {
            PlaceHolder main = new PlaceHolder();
            if (!string.IsNullOrEmpty(Request.QueryString["ContentID"]) || page.Content != null)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["ContentID"]))
                {
                    BusinessObjects.Content c = ContentManager.GetContent(Convert.ToInt32(Request.QueryString["ContentID"], CultureInfo.InvariantCulture));
                    main = base.ParseContent(c.Html, this.Main);
                }
                else
                {
                    main = base.ParseContent(page.Content.Html, this.Main);
                }
            }

            return main;
        }
    }
}